package com.nus.servlets;

import com.nus.beans.ProjectRemark;
import com.nus.beans.UserEvaluation;
import com.nus.database.ProjectsDBManager;
import com.nus.database.UserInfoDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/3/12
 * Time: 2:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class ViewAddUserEvaluationServlet extends AbstractServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String userEvaluationId = request.getParameter("userEvaluation");
        String targetPage = null;
        if(userEvaluationId != null){
            targetPage =  "/WEB-INF/update_user_evaluation.jsp";
            int userEvaluationIdInt = Integer.parseInt(userEvaluationId);
            Connection connection = getUserDatabaseConnection(request);
            UserInfoDBManager userInfoDBManager = new UserInfoDBManager(connection);
            UserEvaluation userEvaluation = userInfoDBManager.getUserEvaluation(userEvaluationIdInt);
            request.setAttribute("userEvaluation", userEvaluation);
        } else {
            targetPage = "/WEB-INF/add_user_evaluation.jsp";
        }
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(targetPage);
        requestDispatcher.forward(request, response);
    }
}
